﻿using System.ComponentModel;
using CoreGraphics;
using JWXH.XH.components;
using JWXH.XH.iOS.components;
using JWXH.XH.utils;
using UIKit;
using Xamarin.Forms;
using Xamarin.Forms.Platform.iOS;

[assembly: ExportRenderer(typeof(EntryNoBorder), typeof(EntryNoBorderRender))]
namespace JWXH.XH.iOS.components
{
    public class EntryNoBorderRender : EntryRenderer
    {
        protected override void OnElementChanged(ElementChangedEventArgs<Entry> e)
        {
            base.OnElementChanged(e);

            if (Control != null)
            {
                // do whatever you want to the UITextField here!
                //                Control.BackgroundColor = UIColor.FromRGB(204, 153, 255);
                //                Control.BorderStyle = UITextBorderStyle.None;
                Control.BorderStyle = UITextBorderStyle.None;
            }
        }

        protected override void OnElementPropertyChanged(object sender, PropertyChangedEventArgs e)
        {
            base.OnElementPropertyChanged(sender, e);
            if (Control != null)
            {
                var finalSender = sender as EntryNoBorder;
                if (!string.IsNullOrEmpty(finalSender.CusBorderColor))
                {
                    Control.Layer.BorderWidth = 1f;
                    var colorArr = TypeUtils.GetRGBAfromString(finalSender.CusBorderColor);
                    Control.Layer.BorderColor = UIColor.FromRGBA(colorArr[1], colorArr[2], colorArr[3], colorArr[0]).CGColor;
                }
        
//                Control.BorderStyle

            }
        }
    }
}